/**
 * 
 */
package demo.tellurium.test.cqp;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.ArrayUtils;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;

import demo.tellurium.framework.BaseTelluriumJUnitTestCase;
import demo.tellurium.module.cqp.CQPAllDocumentsModule;
import demo.tellurium.module.cqp.CQPLoginModule;
import demo.tellurium.module.cqp.CQPProfileModule;

/**
 * @author roger.xu
 * 
 */
public class AllDocumentsJUnitTestCase extends BaseTelluriumJUnitTestCase {
    private static CQPLoginModule cqpLogin;
    private static CQPAllDocumentsModule cqpAllDocuments;
    private static CQPProfileModule cqpProfile;

    @BeforeClass
    public static void initUi() {
        cqpLogin = new CQPLoginModule();
        cqpLogin.defineUi();

        cqpAllDocuments = new CQPAllDocumentsModule();
        cqpAllDocuments.defineUi();

        cqpProfile = new CQPProfileModule();
        cqpProfile.defineUi();
    }

    @Before
    public void delay() {
        waitingDelay();
    }

    @Test
    public void connectTo() {
        String contextUrl = getProperty("cqp.context.url");
        String pagePath = getProperty(CQPAllDocumentsModule.PATH_KEY);
        String url = String.format("%s/%s", contextUrl, pagePath);
        connectUrl(url);
    }

    @Test
    public void testLogin() {
        console.debug("[testLogin]");
        // cqpLogin.doAdminLogin();
        String username = getProperty("cqp.login.username");
        String password = getProperty("cqp.login.password");
        cqpLogin.doLogin(username, password);
        pauseSec(3);
    }

    @Test
    public void testTreeGridCheckBoxes() {
        console.debug("[testTreeGrid]");
        List<Integer> indexes = new ArrayList<Integer>();
        for (int i = 1; i <= 3; i++) {
            indexes.add(i);
        }

        int[] indexesArray = ArrayUtils.toPrimitive(indexes.toArray(new Integer[indexes.size()]));
        cqpAllDocuments.doClickCheckBoxes(indexesArray);
    }

    @Ignore
    @Test
    public void testTreeGridLink() {
        console.debug("[testTreeGridLink]");
        cqpAllDocuments.doClickDocument(1);
        manualBreak();
    }

    @Test
    public void testClickCreateButton() {
        console.debug("[testClickCreateButton]");
        cqpAllDocuments.doClickCreateButton();
    }

    @Ignore
    @Test
    public void testClickCreatePreAssessmentButton() {
        console.debug("[testClickCreatePreAssessmentButton]");
        cqpAllDocuments.doClickCheckBoxes(1);
        cqpAllDocuments.doClickCreatePreAssessmentButton();
        manualBreak();
        cqpProfile.doClickCancelButton();
    }

    @Ignore
    @Test
    public void testClickReportButton() {
        console.debug("[testClickReportButton]");
        cqpAllDocuments.doClickReportButton();
        pauseSec(3);
    }

    @Ignore
    @Test
    public void testClickReportCancelButton() {
        console.debug("[testClickReportCancelButton]");
        cqpAllDocuments.doClickReportDialogCancelButton();
        pauseSec(5);
    }

    @Test
    public void testClickDeleteButton() {
        console.debug("[testClickDeleteButton]");
        cqpAllDocuments.doClickDeleteButton();
    }

    @Ignore
    @Test
    public void testClickDeleteOKButton() {
        console.debug("[testClickDeleteOKButton]");
        cqpAllDocuments.doClickDeleteDialogOKButton();
        cqpAllDocuments.doClickInfoDialogOKButton();
    }

    @Test
    public void testClickDeleteCancelButton() {
        console.debug("[testClickDeleteCancelButton]");
        cqpAllDocuments.doClickDeleteDialogCancelButton();
        pauseSec(3);
    }
}
